package com.example.netty.chatSystem.handler;

import com.example.netty.chatSystem.channelService.ChannelService;
import com.example.netty.chatSystem.message.PingMessage;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@ChannelHandler.Sharable
public class QuitHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        ChannelService.deleteChannel(ctx.channel());
        System.out.println("用户断开连接");
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        ChannelService.deleteChannel(ctx.channel());
        System.out.println("用户异常退出");
    }
}
